﻿using DLL.Standard.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace DLL.MSDM.Entity.Param
{
    internal class CMS_SelectCard
    {
    }

    [Serializable]
    public class CMotionCardType : CNotifyPropertyChanged
    {
        //控制卡类型
        public static string[] CardTypeName = new string[]
        {
            "TMCM6110And1110_USB",
            "TMCM6214And1110_USB"
        };

        public static string[] CardTypeName4 = new string[]
        {
            "Vince_VSMD",
            "Vince_RJCX"
        };

        public static string[] DevTypeName = new string[]
        {
            "MS6_ROBOT",
            "MS4_ROBOT"
        };

        public static string[] djNameS = new string[] { "ZL", "SCS", "FS" };
        private int _motionCardType = 0;

        public int MotionCardType
        {
            get { return _motionCardType; }
            set
            {
                if (_motionCardType != value)
                {
                    _motionCardType = value;
                    this.OnPropertyChanged();
                }
            }
        }

        //设备类型0：多工位配药机器人 1：双工位配药机器人
        private int _deviceType = 0;

        public int DeviceType
        {
            get { return _deviceType; }
            set
            {
                if (_deviceType != value)
                {
                    _deviceType = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _djType = 0;

        public int DjType
        {
            get { return _djType; }
            set { _djType = value; OnPropertyChanged(); }
        }
    }

    public class CWR_MotionCardType : CNotifyPropertyChanged
    {
        private CMotionCardType _obj;

        public CMotionCardType Obj
        {
            get { return _obj; }
            set
            {
                if (_obj != value)
                {
                    _obj = value;
                    this.OnPropertyChanged();
                }
            }
        }

        public bool ReadParam()
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(CMotionCardType));
            //string str2 = Application.StartupPath;
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            string filePath = str_1 + @"Param\CardType.xml";
            if (File.Exists(filePath))
            {
                Stream fstream = File.OpenRead(filePath);
                Obj = (CMotionCardType)xmlFormat.Deserialize(fstream);
                fstream.Close();
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool SaveParam(CMotionCardType obj)
        {
            try
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(CMotionCardType));
                //现在将数据保存到本地的一个文件中
                string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
                string filePath = str_1 + @"Param\CardType.xml";
                Stream fstream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                xmlFormat.Serialize(fstream, obj);
                fstream.Close();
                return true;
            }
            catch (Exception e)
            {
                string str = e.Message;
                return false;
            }
        }

        public int GetCardTypeID()
        {
            int CardID = 0;
            switch (Obj.DeviceType)
            {
                case 0:
                    {
                        //六工位配药机，trinamic 控制卡
                        CardID = 0;
                        break;
                    }
                case 1:
                    {
                        //四工位配药机器人，vince 控制卡
                        CardID = 4;
                        break;
                    }
                case 2:
                    {
                        //双工位粉针
                        CardID = 4;//new CMotionCtrlVsmd(); //
                        break;
                    }
                case 3:
                    {
                        //剥盖机
                        CardID = 5;//new CMotionCtrlVsmd(); //
                        break;
                    }
                case 4:
                    {
                        //安瓿瓶，水针
                        CardID = 4;//new CMotionCtrlVsmd(); //
                        break;
                    }
                case 5:
                    {
                        //控制卡调试
                        CardID = Obj.MotionCardType;
                        break;
                    }
                default:
                    {
                        CardID = Obj.MotionCardType;
                        break;
                    }
            }
            return CardID;
        }
    }

    public class CDJ_Type : CNotifyPropertyChanged
    {
        private int _djType = 0;

        public int DjType
        {
            get { return _djType; }
            set { _djType = value; OnPropertyChanged(); }
        }

        public static string[] djNameS = new string[] { "ZL", "SCS", "FS" };
    }

    public class CDJ_Type_WR : CNotifyPropertyChanged
    {
        private CDJ_Type _djParam = new CDJ_Type();

        public CDJ_Type DjParam
        {
            get { return _djParam; }
            set
            {
                if (_djParam != value)
                {
                    _djParam = value;
                    OnPropertyChanged();
                }
            }
        }

        public virtual bool ReadParam()
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(CDJ_Type));
            //string str2 = Application.StartupPath;
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            string filePath = str_1 + @"Param\DjType.xml";
            if (File.Exists(filePath))
            {
                Stream fstream = File.OpenRead(filePath);
                _djParam = (CDJ_Type)xmlFormat.Deserialize(fstream);
                fstream.Close();
                return true;
            }
            else
            {
                return false;
            }
        }

        public virtual bool SaveParam()
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(CDJ_Type));
            //现在将数据保存到本地的一个文件中
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            string fileFoldPath = str_1 + @"Param";
            if (Directory.Exists(fileFoldPath) == false)
            {
                Directory.CreateDirectory(fileFoldPath);
            }
            string filePath = str_1 + @"Param\DjType.xml";
            Stream fstream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
            xmlFormat.Serialize(fstream, _djParam);
            fstream.Close();
            return true;
        }
    }
}